home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Sound / WaveTable Sounds / Source / WaveTableSynthPlay.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  1.7 KB  |  95 lines  |  [TEXT/CWIE]

  1. /*
  2.     WaveTableSynthPlay     12:32:47 PM  10/13/92 • Brigham Stevens
  3.     
  4.     Shows how to use the waveTableSynth
  5.     
  6.     InitDialogs is called only to install crash handler in case
  7.     no Debugger exists.
  8.  
  9.     BuildProgram WaveTableSynthPlay
  10. */
  11.  
  12. #include <Dialogs.h>
  13. #include <Sound.h>
  14. #include <Memory.h>
  15.  
  16. #define WAVE_SIZE (512*50)
  17.  
  18. void WaveTableSynthPlay();
  19.  
  20. void WaveTableSynthPlay()
  21. {
  22.     SndChannelPtr    chan;
  23.     SndCommand        mycmd;
  24.     unsigned char    *wave;
  25.     unsigned char    *waveSurfer;
  26.     short            soundByte;
  27.     short            change = 0;
  28.     short            err;
  29.     long            tickTime;
  30.  
  31.     /* Nab some memory for a waveTable to build our sound */
  32.     wave = (unsigned char *) NewPtr (WAVE_SIZE);
  33.     if(!wave) {
  34.         DebugStr("\pNewPtr failed to make wave...");
  35.         return;
  36.     }
  37.  
  38.     /* create a channel linked with the waveTableSynth */        
  39.     chan = nil;
  40.     err = SndNewChannel (&chan, waveTableSynth, 0x07, nil);
  41.     if (err) {
  42.         DebugStr("\p error SndNewChannel [1]");
  43.         goto bail;
  44.     }
  45.     
  46.     /* generate a cool wave */
  47.     waveSurfer = wave;
  48.     for (soundByte = 0; soundByte <= WAVE_SIZE; ++soundByte) {
  49.         *waveSurfer++ = change++;
  50.         if(change > WAVE_SIZE / 4) {
  51.             change += 44;
  52.         }
  53.     }
  54.     
  55.     /* install the wave */
  56.     mycmd.cmd = waveTableCmd;
  57.     mycmd.param1 = WAVE_SIZE;
  58.     mycmd.param2 = (long)wave;
  59.     
  60.     err = SndDoImmediate (chan, &mycmd);
  61.     if (err) {
  62.         DebugStr("\p error SndDoImmediate [1]");
  63.         goto bail;
  64.     }
  65.  
  66.     /* play the wave */
  67.     mycmd.cmd = freqCmd;
  68.     mycmd.param1 = 0;
  69.     mycmd.param2 = 20;
  70.     
  71.     err = SndDoImmediate (chan, &mycmd);
  72.     if (err) {
  73.         DebugStr("\p error SndDoImmediate [2]");
  74.         goto bail;
  75.     }
  76.  
  77.     Delay(180,&tickTime);
  78.     
  79.     /* Now dump the channel */
  80.     err = SndDisposeChannel (chan,false);
  81.     if (err) {
  82.         DebugStr("\p error SndDisposeChannel [1]");
  83.         goto bail;
  84.     }
  85.  
  86. bail:
  87.     DisposePtr((char *)wave);
  88. }
  89.  
  90.  
  91.  
  92. void main()
  93. {
  94.     WaveTableSynthPlay();
  95. }